<template>
  <div class="deliver_list">
    <!--出库列表操作 -->
    <el-row class="deliver_operation">
      <el-col :span="20">
        <div class="title">出库列表</div>
      </el-col>
      <el-col :span="4">
        <el-tooltip class="item" effect="light" content="待定"  placement="top">
          <el-button type="info" class="iconfont icon-shenhe" @click="pendingOrderPopups" circle></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="light" content="通过" placement="top">
          <el-button type="success" class="iconfont icon-tongguos" @click="acceptOrderPopups" circle></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="light" content="拒绝" placement="top">
          <el-button type="danger" class="iconfont icon-butongguo" @click="refuseOrderPopups" circle></el-button>
        </el-tooltip>
        <!-- <el-button type="primary" class="iconfont icon-tianjia" circle></el-button>
        <el-button type="warning" class="iconfont icon-xiugai"  circle></el-button>
        <el-button type="danger" class="iconfont icon-changyonggoupiaorenshanchu"  circle></el-button> -->
      </el-col>
    </el-row>
    <!-- 出库列表 -->
    <el-table
        :data="deliverList"
        border
        @selection-change="selectTarget"
    >
      <!-- 全选 -->
      <el-table-column type="selection" width="40"/>
      <!-- 展开行 -->
      <el-table-column type="expand">
        <template slot-scope="scope">
          <el-card>
            <!-- 药品信息 -->
            <el-divider content-position="left">药品信息</el-divider>
            <div class="description">类别描述：{{scope.row.medicine.medicineTypeVo.description}}</div>
            <div class="specification">规格：{{scope.row.medicine.specification}}</div>
            <div class="efficacy">作用：{{scope.row.medicine.efficacy}}</div>
            <el-row class="medicine_info_row1">
              <el-col :span="4">
                <div class="level">药品类别：{{scope.row.medicine.medicineTypeVo.type}}</div>
              </el-col>
              <el-col :span="4">
                <div class="purchasePrice">进货价格：{{scope.row.medicine.purchasePrice}}元/盒</div>
              </el-col>
              <el-col :span="4">
                <div class="retailPrice">零售价格：{{scope.row.medicine.retailPrice}}元/盒</div>
              </el-col>
              <el-col :span="4">
                <div class="number">出库数量：{{scope.row.number}}盒</div>
              </el-col>
              <el-col :span="4">
                是否有医保：
                <el-tag :type="scope.row.medicine.medicalInsurance == '医保' ? '' : 'info'">{{ scope.row.medicine.medicalInsurance }}</el-tag>
              </el-col>
              <el-col :span="4">
                是否为捐赠物资：
                <el-tag :type="scope.row.medicine.donate == '捐赠' ? 'success' : 'info'">{{ scope.row.medicine.donate }}</el-tag>
              </el-col>
            </el-row>
            <!-- 第三方信息 -->
            <el-divider content-position="left">第三方信息</el-divider>
            <el-row class="medicine_info_row2">
              <el-col :span="5">
                <div class="contactNumber">联系电话：{{scope.row.thirdParty.contactNumber}}</div>
              </el-col>
              <el-col :span="6">
                <div class="address">地址：{{scope.row.thirdParty.address}}</div>
              </el-col>
              <el-col :span="13">
                <div class="remark">备注：{{scope.row.thirdParty.remark}}</div>
              </el-col>
            </el-row>
            <!-- 审核时间轴 -->
            <el-divider content-position="left">审核时间轴</el-divider>
            <el-timeline>
              <el-timeline-item
                v-for="activity in scope.row.historiesVoList"
                :key="activity.timestamp"
                :icon="activity.icon"
                :type="activity.type"
                :color="activity.color"
                :size="activity.size"
                :timestamp="activity.timestamp">
                {{activity.content}}
              </el-timeline-item>
            </el-timeline>
          </el-card>
        </template>
      </el-table-column>
      <!-- 药品图片 -->
      <el-table-column prop="medicine" label="药品图片" width="150" align="center">
        <template slot-scope="scope">
          <img :src="'http://47.107.237.85/mdps/img/'+scope.row.medicine.img" alt="图片加载错误">
        </template> 
      </el-table-column>
      <!-- 药品名称 -->
      <el-table-column prop="medicine.name" label="药品名称" width="150" align="center"/>
      <!-- 供应商 -->
      <el-table-column prop="supplier" label="供应商" width="170px" align="center"/>
      <!-- 仓库 -->
      <el-table-column prop="warehouse" label="仓库" width="120px" align="center"/>
      <!-- 第三方 -->
      <el-table-column prop="thirdParty.buyer" label="第三方" width="150px" align="center"/>
      <!-- 出库总金额 -->
      <el-table-column prop="aggregateAmount" label="出库总金额" width="100px" align="center"/>
      <!-- 下单时间 -->
      <el-table-column prop="orderTime" label="下单时间" width="170px" align="center"/>
      <!-- 下单人 -->
      <el-table-column prop="orderBy" label="下单人" width="100px" align="center"/>
      <!-- 订单状态 -->
      <el-table-column prop="state" label="订单状态" align="center">
        <template slot-scope="scope">
          <el-tag type="info" v-show="scope.row.state == '待审核'">{{ scope.row.state }}</el-tag>
          <el-tag type="success" v-show="scope.row.state == '已通过'">{{ scope.row.state }}</el-tag>
          <el-tag type="danger" v-show="scope.row.state == '已拒绝'">{{ scope.row.state }}</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <!-- 员工分页 -->
    <el-pagination
        @size-change="handleDeliverTableSizeChange"
        @current-change="handleDeliverTableCurrentChange"
        :current-page="deliverPageList.currentPage"
        :page-sizes="[5, 10, 15, 20, 30]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="deliverTotal">
    </el-pagination>
    <!-- 待定订单确认框-->
    <el-dialog title="请确认您的操作" :visible.sync="showPendingOrder" width="30%" append-to-body>
      <el-row>
          <el-col :span="3">
            <svg t="1652248818186" class="icon" viewBox="0 0 1040 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4020" width="32" height="32"><path d="M133.534106 982.154208c-78.393906 0-113.368619-57.111137-77.716004-126.943393L444.214002 94.571489c35.652615-69.819703 95.023424-70.359514 131.931412-1.200974L983.376105 856.40342c36.916357 69.166909 2.975236 125.759158-75.410301 125.759157H133.534106v-0.008369z" fill="#FFB624" p-id="4021"></path><path d="M203.655099 894.734165c-63.208068 0-91.412132-50.687808-62.668258-112.661425l313.17809-675.060497c28.743874-61.965248 76.619645-62.44229 106.380372-1.062883l328.372297 677.182078c29.764912 61.387776 2.397764 111.611096-60.801936 111.611096H203.655099v-0.008369z" fill="#FFD91C" p-id="4022"></path><path d="M468.442715 376.22296v223.305883c0 28.88615 23.416905 52.30724 52.30724 52.307239 28.88615 0 52.30724-23.42109 52.30724-52.307239V376.22296c0-28.890335-23.42109-52.30724-52.30724-52.30724-28.890335 0-52.30724 23.416905-52.30724 52.30724zM468.442715 765.819834v33.254851c0 28.881965 23.416905 52.30724 52.30724 52.30724 28.88615 0 52.30724-23.425274 52.30724-52.30724v-33.254851c0-28.88615-23.42109-52.30724-52.30724-52.307239-28.890335 0-52.30724 23.42109-52.30724 52.307239z" fill="#6E6E96" p-id="4023"></path><path d="M133.534106 961.231312c-30.354937 0-53.006064-9.687301-63.781356-27.28764s-9.105644-42.180558 4.699283-69.217124l388.3959-760.635141c13.327885-26.103405 30.47629-41.159521 47.051408-41.310166 16.570934-0.150645 33.991337 14.591628 47.787894 40.443958l407.230692 763.032905c14.256861 26.714353 16.407735 50.934698 6.046717 68.20864-10.361018 17.265574-32.727594 26.768753-62.99884 26.768753H133.534106a20.922896 20.922896 0 1 1 0-0.004185z m0 41.849977h774.440067c45.549144 0 80.661948-16.729948 98.881606-47.101623 18.219658-30.37586 16.441212-69.242232-5.013126-109.435115L594.603593 83.520016c-21.701228-40.661556-51.913889-62.89004-85.085048-62.588751-33.171159 0.30129-62.977917 23.07377-83.942659 64.124491L37.179986 845.695081c-20.676006 40.502542-21.784919 79.59488-3.113327 110.100463 18.667408 30.493028 53.98944 47.28156 99.471632 47.28156a20.922896 20.922896 0 0 1-0.004185 0.004185z" fill="#6E6E96" p-id="4024"></path></svg>
          </el-col>
          <el-col :span="21">
            <div class="showPendingOrder">确定要将该订单的状态变为待审核吗？</div>
          </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showPendingOrder = false">取消</el-button>
        <el-button type="primary" @click="pendingOrder">确认</el-button>
      </span>
    </el-dialog>
    <!-- 通过订单确认框-->
    <el-dialog title="请确认您的操作" :visible.sync="showAcceptOrder" width="30%" append-to-body>
      <el-row>
          <el-col :span="3">
            <svg t="1652248818186" class="icon" viewBox="0 0 1040 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4020" width="32" height="32"><path d="M133.534106 982.154208c-78.393906 0-113.368619-57.111137-77.716004-126.943393L444.214002 94.571489c35.652615-69.819703 95.023424-70.359514 131.931412-1.200974L983.376105 856.40342c36.916357 69.166909 2.975236 125.759158-75.410301 125.759157H133.534106v-0.008369z" fill="#FFB624" p-id="4021"></path><path d="M203.655099 894.734165c-63.208068 0-91.412132-50.687808-62.668258-112.661425l313.17809-675.060497c28.743874-61.965248 76.619645-62.44229 106.380372-1.062883l328.372297 677.182078c29.764912 61.387776 2.397764 111.611096-60.801936 111.611096H203.655099v-0.008369z" fill="#FFD91C" p-id="4022"></path><path d="M468.442715 376.22296v223.305883c0 28.88615 23.416905 52.30724 52.30724 52.307239 28.88615 0 52.30724-23.42109 52.30724-52.307239V376.22296c0-28.890335-23.42109-52.30724-52.30724-52.30724-28.890335 0-52.30724 23.416905-52.30724 52.30724zM468.442715 765.819834v33.254851c0 28.881965 23.416905 52.30724 52.30724 52.30724 28.88615 0 52.30724-23.425274 52.30724-52.30724v-33.254851c0-28.88615-23.42109-52.30724-52.30724-52.307239-28.890335 0-52.30724 23.42109-52.30724 52.307239z" fill="#6E6E96" p-id="4023"></path><path d="M133.534106 961.231312c-30.354937 0-53.006064-9.687301-63.781356-27.28764s-9.105644-42.180558 4.699283-69.217124l388.3959-760.635141c13.327885-26.103405 30.47629-41.159521 47.051408-41.310166 16.570934-0.150645 33.991337 14.591628 47.787894 40.443958l407.230692 763.032905c14.256861 26.714353 16.407735 50.934698 6.046717 68.20864-10.361018 17.265574-32.727594 26.768753-62.99884 26.768753H133.534106a20.922896 20.922896 0 1 1 0-0.004185z m0 41.849977h774.440067c45.549144 0 80.661948-16.729948 98.881606-47.101623 18.219658-30.37586 16.441212-69.242232-5.013126-109.435115L594.603593 83.520016c-21.701228-40.661556-51.913889-62.89004-85.085048-62.588751-33.171159 0.30129-62.977917 23.07377-83.942659 64.124491L37.179986 845.695081c-20.676006 40.502542-21.784919 79.59488-3.113327 110.100463 18.667408 30.493028 53.98944 47.28156 99.471632 47.28156a20.922896 20.922896 0 0 1-0.004185 0.004185z" fill="#6E6E96" p-id="4024"></path></svg>
          </el-col>
          <el-col :span="21">
            <div class="showPendingOrder">确定要将该订单的状态变为已通过吗？</div>
          </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showAcceptOrder = false">取消</el-button>
        <el-button type="primary" @click="acceptOrder">确认</el-button>
      </span>
    </el-dialog>
    <!-- 拒绝订单确认框-->
    <el-dialog title="请确认您的操作" :visible.sync="showRefuseOrder" width="30%" append-to-body>
      <el-row>
          <el-col :span="3">
            <svg t="1652248818186" class="icon" viewBox="0 0 1040 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4020" width="32" height="32"><path d="M133.534106 982.154208c-78.393906 0-113.368619-57.111137-77.716004-126.943393L444.214002 94.571489c35.652615-69.819703 95.023424-70.359514 131.931412-1.200974L983.376105 856.40342c36.916357 69.166909 2.975236 125.759158-75.410301 125.759157H133.534106v-0.008369z" fill="#FFB624" p-id="4021"></path><path d="M203.655099 894.734165c-63.208068 0-91.412132-50.687808-62.668258-112.661425l313.17809-675.060497c28.743874-61.965248 76.619645-62.44229 106.380372-1.062883l328.372297 677.182078c29.764912 61.387776 2.397764 111.611096-60.801936 111.611096H203.655099v-0.008369z" fill="#FFD91C" p-id="4022"></path><path d="M468.442715 376.22296v223.305883c0 28.88615 23.416905 52.30724 52.30724 52.307239 28.88615 0 52.30724-23.42109 52.30724-52.307239V376.22296c0-28.890335-23.42109-52.30724-52.30724-52.30724-28.890335 0-52.30724 23.416905-52.30724 52.30724zM468.442715 765.819834v33.254851c0 28.881965 23.416905 52.30724 52.30724 52.30724 28.88615 0 52.30724-23.425274 52.30724-52.30724v-33.254851c0-28.88615-23.42109-52.30724-52.30724-52.307239-28.890335 0-52.30724 23.42109-52.30724 52.307239z" fill="#6E6E96" p-id="4023"></path><path d="M133.534106 961.231312c-30.354937 0-53.006064-9.687301-63.781356-27.28764s-9.105644-42.180558 4.699283-69.217124l388.3959-760.635141c13.327885-26.103405 30.47629-41.159521 47.051408-41.310166 16.570934-0.150645 33.991337 14.591628 47.787894 40.443958l407.230692 763.032905c14.256861 26.714353 16.407735 50.934698 6.046717 68.20864-10.361018 17.265574-32.727594 26.768753-62.99884 26.768753H133.534106a20.922896 20.922896 0 1 1 0-0.004185z m0 41.849977h774.440067c45.549144 0 80.661948-16.729948 98.881606-47.101623 18.219658-30.37586 16.441212-69.242232-5.013126-109.435115L594.603593 83.520016c-21.701228-40.661556-51.913889-62.89004-85.085048-62.588751-33.171159 0.30129-62.977917 23.07377-83.942659 64.124491L37.179986 845.695081c-20.676006 40.502542-21.784919 79.59488-3.113327 110.100463 18.667408 30.493028 53.98944 47.28156 99.471632 47.28156a20.922896 20.922896 0 0 1-0.004185 0.004185z" fill="#6E6E96" p-id="4024"></path></svg>
          </el-col>
          <el-col :span="21">
            <div class="showPendingOrder">确定要将该订单的状态变为已拒绝吗？</div>
          </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showRefuseOrder = false">取消</el-button>
        <el-button type="primary" @click="refuseOrder">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'deliverList',
    data() {
      return {
        /* 出库列表列表 */
        deliverList: [],
        /* 出库列表表分页信息 */
        deliverPageList:{
          pageNo: 1,
          pageSize: 5,
          currentPage: 1,
          orderTime: '',
          orderBy: '',
          state: '',
          thirdParty: '',
        },
        /* 药品表总条数 */
        deliverTotal: 0,

        /* 选中出库个数 */
        selectedDeliverNumber: 0,
        /* 选中出库数组 */
        selectedDeliver: [],

        /* 控制待定订单弹出层 */
        showPendingOrder: false,
        /* 控制通过订单弹出层 */
        showAcceptOrder: false,
        /* 控制拒绝订单弹出层 */
        showRefuseOrder: false,

        /* 当前登录用户 */
        changeOrderStateForm: {
          currentUserId: '',
          currentOrderId: '',
          state: '',
        }
      }
    },
    methods: {
      /* 复选框选择目标事件回调 */
      selectTarget(selection) {
          this.selectedDeliverNumber =  selection.length
          this.selectedDeliver = selection
      },

      /* 待定订单弹出层 */
      pendingOrderPopups() {
        if(this.selectedDeliverNumber > 1) {
            this.$message.error('不能同时操作多个订单!')
            return
        }
        if(this.selectedDeliverNumber < 1) {
            this.$message.error('请选择需要操作的订单!')
            return
        }
        this.changeOrderStateForm.currentOrderId = this.selectedDeliver[0].id
        this.showPendingOrder = true
      },
      /* 待定订单 */
      async pendingOrder() {

        this.changeOrderStateForm.state = "待审核"

        const { data: res } = await this.$http.post('workbench/deliver/editOrderState.do',this.changeOrderStateForm)
        if (res.code == '1') {
          this.showPendingOrder = false
          this.getDeliverPageList()
          this.getDeliverTotal()
          this.$message.success('更改订单状态成功!')
        } else {
          this.$message.error('更改订单状态失败!')
        }
      },

      /* 通过订单弹出层 */
      acceptOrderPopups() {
        if(this.selectedDeliverNumber > 1) {
            this.$message.error('不能同时操作多个订单!')
            return
        }
        if(this.selectedDeliverNumber < 1) {
            this.$message.error('请选择需要操作的订单!')
            return
        }
        this.changeOrderStateForm.currentOrderId = this.selectedDeliver[0].id
        this.showAcceptOrder = true
      },
      /* 通过订单 */
      async acceptOrder() {

        this.changeOrderStateForm.state = "已通过"

        const { data: res } = await this.$http.post('workbench/deliver/editOrderState.do',this.changeOrderStateForm)
        if (res.code == '1') {
          this.showAcceptOrder = false
          this.getDeliverPageList()
          this.getDeliverTotal()
          this.$message.success('更改订单状态成功!')
        } else {
          this.$message.error('更改订单状态失败!')
        }
      },

      /* 拒绝订单弹出层 */
      refuseOrderPopups() {
        if(this.selectedDeliverNumber > 1) {
            this.$message.error('不能同时操作多个订单!')
            return
        }
        if(this.selectedDeliverNumber < 1) {
            this.$message.error('请选择需要操作的订单!')
            return
        }
        this.changeOrderStateForm.currentOrderId = this.selectedDeliver[0].id
        this.showRefuseOrder = true
      },
      /* 拒绝订单 */
      async refuseOrder() {

        this.changeOrderStateForm.state = "已拒绝"

        const { data: res } = await this.$http.post('workbench/deliver/editOrderState.do',this.changeOrderStateForm)
        if (res.code == '1') {
          this.showRefuseOrder = false
          this.getDeliverPageList()
          this.getDeliverTotal()
          this.$message.success('更改订单状态成功!')
        } else {
          this.$message.error('更改订单状态失败!')
        }
      },

      /* 分页获得出库列表 */
      async getDeliverPageList(deliver) {

        if(deliver != undefined) {
          this.deliverPageList.orderTime = deliver.orderTime
          this.deliverPageList.orderBy = deliver.orderBy
          this.deliverPageList.state = deliver.state
          this.deliverPageList.thirdParty = deliver.thirdParty
        }

        const { data: res } = await this.$http.post('workbench/deliver/deliverPageList.do',this.deliverPageList)
        if (res.code == '1') {
          this.deliverList = res.others
        } else {
          this.$message.error('获取出库表失败!')
        }
      },
      /* 获得出库列表总条数 */
      async getDeliverTotal() {
          const { data: res } = await this.$http.post('workbench/deliver/getDeliverTotal.do',this.deliverPageList)
          if (res.code == '1') {
            this.deliverTotal = res.number
          } else {
              this.$message.error('获取目标表总条数失败!')
          }
      },
      /* 处理分页每页显示几行 */
      handleDeliverTableSizeChange(val) {
          this.DeliverPageList.pageSize = val
          this.getDeliverTotal()
          this.getDeliverPageList()
      },
      /* 处理分页切换页数 */
      handleDeliverTableCurrentChange(val) {
          this.DeliverPageList.pageNo = val
          this.getDeliverTotal()
          this.getDeliverPageList()
      },

      /* 初始化当前登录用户 */
      getCurrentUser() {
        let user = JSON.parse(window.localStorage.getItem('user'))
        this.changeOrderStateForm.currentUserId = user.id
      },
    },
    created() {
      this.getCurrentUser()
      this.getDeliverTotal()
      this.getDeliverPageList()
    },
    mounted() {
      this.$bus.$on('getDeliverPageList',this.getDeliverPageList)
      this.$bus.$on('getDeliverTotal',this.getDeliverTotal)
    },
    beforeDestroy() {
      this.$bus.$off('getDeliverPageList')
      this.$bus.$off('getDeliverTotal')
    }
  }
</script>

<style scoped>
/* 出库列表列表 */
.deliver_list {
  margin: 0px 20px;
  box-shadow: 0 0 10px rgb(220, 223, 220);
}
/* 出库列表列表操作 */
.deliver_operation {
  background-color: #fff;
  margin: 0px 0px;
  height: 70px;
}
.deliver_operation .title {
  line-height: 70px;
  margin-left: 15px;
  font-weight: bold;
}
.deliver_operation .el-button {
  margin-top: 15px;
}
/* 采购按钮 */
.purchaseBtn {
  float: right;
  margin-right: 50px;
}
/* 药品图片 */
.el-table img {
  width: 120px;
}
/* 药品卡片展示 */
.el-table .el-card {
  margin: 10px 30px;
}
.el-table .el-card .purchasePrice,.retailPrice,.level{
  line-height: 30px;
}
.el-table .el-card .description,.specification,.efficacy{
  margin-bottom: 15px;
}
/* 药品折叠栏展示 */
.medicine_info_row1 {
  margin-bottom: 50px;
}
/* 药品折叠栏展示 */
.medicine_info_row2 {
  margin-bottom: 15px;
}
.remark {
  margin-bottom: 30px;
}
.el-timeline {
  margin-top: 30px;
}
/* 出库列表分页 */
.el-pagination {
  text-align: center;
  padding: 15px 0px;
  background-color: #fff;
}
</style>
